package com.ruoyi.teaching.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.ruoyi.teaching.domain.vo.InterviewMaseryList;
import com.ruoyi.teaching.domain.vo.RelatedInterviewVo;
import com.ruoyi.teaching.domain.vo.SelectInterviewMasery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.HighInterview;
import com.ruoyi.teaching.service.IHighInterviewService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 高频面试题Controller
 *
 * @author sunshine
 * @date 2024-01-25
 */
@RestController
@RequestMapping("/interview")
public class HighInterviewController extends BaseController
{
    @Autowired
    private IHighInterviewService highInterviewService;

    /**
     * 查询面试掌握情况记录列表
     */
    @RequiresPermissions("teaching:interview:list")
    @GetMapping("/list/mastery")
    public TableDataInfo listInterviewMastery(@Valid SelectInterviewMasery selectInterviewMasery)
    {
        List<InterviewMaseryList> list = highInterviewService.listInterviewMastery(selectInterviewMasery);
        return getDataTable(list);
    }
    @RequiresPermissions("teaching:interview:list")
    @PutMapping("/exportEs")
    public AjaxResult exportEs()
    {
        highInterviewService.exportEs();
        return AjaxResult.success();
    }
    @RequiresPermissions("teaching:interview:list")
    @GetMapping("/list/related")
    public AjaxResult queryRelatedInterview(@RequestParam("cdId") Long cdId,@RequestParam("courseContent") String courseContent)
    {
        RelatedInterviewVo list = highInterviewService.queryRelatedInterview(cdId,courseContent);
        return AjaxResult.success(list);
    }
    /**
     * 查询高频面试题列表
     */
    @RequiresPermissions("teaching:interview:list")
    @GetMapping("/list")
    public TableDataInfo list(HighInterview highInterview)
    {
        startPage();
        List<HighInterview> list = highInterviewService.selectHighInterviewList(highInterview);
        return getDataTable(list);
    }

    /**
     * 导出高频面试题列表
     */
    @RequiresPermissions("teaching:interview:export")
    @Log(title = "高频面试题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HighInterview highInterview)
    {
        List<HighInterview> list = highInterviewService.selectHighInterviewList(highInterview);
        ExcelUtil<HighInterview> util = new ExcelUtil<HighInterview>(HighInterview.class);
        util.exportExcel(response, list, "高频面试题数据");
    }

    /**
     * 获取高频面试题详细信息
     */
    @RequiresPermissions("teaching:interview:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(highInterviewService.selectHighInterviewById(id));
    }

    /**
     * 新增高频面试题
     */
    @RequiresPermissions("teaching:interview:add")
    @Log(title = "高频面试题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HighInterview highInterview)
    {
        return toAjax(highInterviewService.insertHighInterview(highInterview));
    }

    /**
     * 修改高频面试题
     */
    @RequiresPermissions("teaching:interview:edit")
    @Log(title = "高频面试题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HighInterview highInterview)
    {
        return toAjax(highInterviewService.updateHighInterview(highInterview));
    }

    /**
     * 删除高频面试题
     */
    @RequiresPermissions("teaching:interview:remove")
    @Log(title = "高频面试题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(highInterviewService.deleteHighInterviewByIds(ids));
    }
}
